package com.atguigu.dao.impl;

import com.atguigu.dao.TomcatAndHeartbeatServiceConfigDao;
import com.atguigu.pojo.TomcatAndHeartbeatServiceConfig;

import java.util.List;

public class TomcatAndHeartbeatServiceConfigDaoImpl extends BaseDao implements TomcatAndHeartbeatServiceConfigDao {
    @Override
    public int addTomcatAndHeartbeatServiceConfig(TomcatAndHeartbeatServiceConfig tomcatAndHeartbeatServiceConfig) {
        System.out.println("TomcatAndHeartbeatServiceConfigDaoImpl 程序在["+Thread.currentThread().getName()+"]线程中");
        String sql="insert into t_tomcatAndHeartbeatServiceConfig(`id`,`serverId`,`serviceId`,`tomcatHome`,`javaHome`,`maxMemory`,`httpPort`,`shutdownPort`,`projectId`,`moduleId`,`use`,`heartbeat`) values(?,?,?,?,?,?,?,?,?,?,?,?);";
            return update(sql,tomcatAndHeartbeatServiceConfig.getId(),tomcatAndHeartbeatServiceConfig.getServerId(),
                    tomcatAndHeartbeatServiceConfig.getServiceId(),tomcatAndHeartbeatServiceConfig.getTomcatHome(),tomcatAndHeartbeatServiceConfig.getJavaHome(),tomcatAndHeartbeatServiceConfig.getMaxMemory(),
                    tomcatAndHeartbeatServiceConfig.getHttpPort(),tomcatAndHeartbeatServiceConfig.getShutdownPort(),tomcatAndHeartbeatServiceConfig.getProjectId(),
                    tomcatAndHeartbeatServiceConfig.getModuleId(),tomcatAndHeartbeatServiceConfig.getUse(),tomcatAndHeartbeatServiceConfig.getHeartbeat());
    }

    @Override
    public int deleteTomcatAndHeartbeatServiceConfigById(String id) {
        String sql="delete from t_tomcatAndHeartbeatServiceConfig where id=?";
        return update(sql,id);
    }

    @Override
    public int updateTomcatAndHeartbeatServiceConfig(TomcatAndHeartbeatServiceConfig tomcatAndHeartbeatServiceConfig) {
        String sql="update t_tomcatAndHeartbeatServiceConfig set `serverId`=?,`serviceId`=?,`tomcatHome`=?,`javaHome`=?,`maxMemory`=?,`httpPort`=?,`shutdownPort`=?,`projectId`=?,`moduleId`=?,`use`=?,`heartbeat`=? where id=?";
        return update(sql,tomcatAndHeartbeatServiceConfig.getServerId(),
                tomcatAndHeartbeatServiceConfig.getServiceId(),tomcatAndHeartbeatServiceConfig.getTomcatHome(),
                tomcatAndHeartbeatServiceConfig.getJavaHome(),tomcatAndHeartbeatServiceConfig.getMaxMemory(),tomcatAndHeartbeatServiceConfig.getHttpPort(),tomcatAndHeartbeatServiceConfig.getShutdownPort(),tomcatAndHeartbeatServiceConfig.getProjectId(),tomcatAndHeartbeatServiceConfig.getModuleId(),tomcatAndHeartbeatServiceConfig.getUse(),tomcatAndHeartbeatServiceConfig.getHeartbeat(),tomcatAndHeartbeatServiceConfig.getId());
    }

    @Override
    public TomcatAndHeartbeatServiceConfig queryTomcatAndHeartbeatServiceConfigById(String id) {
        String sql ="select `id`,`serverId`,`serviceId`,`tomcatHome`,`javaHome`,`maxMemory`,`httpPort`,`shutdownPort`,`projectId`,`moduleId`,`use`,`heartbeat` from t_tomcatAndHeartbeatServiceConfig where id=?";
        return queryForOne(TomcatAndHeartbeatServiceConfig.class,sql,id);
    }

    @Override
    public List<TomcatAndHeartbeatServiceConfig> queryTomcatAndHeartbeatServiceConfigs() {
        String sql ="select `id`,`serverId`,`serviceId`,`tomcatHome`,`javaHome`,`maxMemory`,`httpPort`,`shutdownPort`,`projectId`,`moduleId`,`use`,`heartbeat`  from t_tomcatAndHeartbeatServiceConfig";
        return queryForList(TomcatAndHeartbeatServiceConfig.class,sql);
    }
    @Override
    public TomcatAndHeartbeatServiceConfig queryTomcatAndHeartbeatServiceConfigByServiceId(String serviceId){
        String sql ="select `id`,`serverId`,`serviceId`,`tomcatHome`,`javaHome`,`maxMemory`,`httpPort`,`shutdownPort`,`projectId`,`moduleId`,`use`,`heartbeat` from t_tomcatAndHeartbeatServiceConfig where serviceId =?";
        return queryForOne(TomcatAndHeartbeatServiceConfig.class,sql,serviceId);
    }
    @Override
    public List<TomcatAndHeartbeatServiceConfig> queryTomcatAndHeartbeatServiceConfigsByProjectModuleId(String projectModuleId){
        String sql ="select `id`,`serverId`,`serviceId`,`tomcatHome`,`javaHome`,`maxMemory`,`httpPort`,`shutdownPort`,`projectId`,`moduleId`,`use`,`heartbeat` from t_tomcatAndHeartbeatServiceConfig where moduleId =?";
        return queryForList(TomcatAndHeartbeatServiceConfig.class,sql,projectModuleId);
    }

    @Override
    public Integer queryForPageTotalCount() {
        String sql="select count(*) from t_tomcatAndHeartbeatServiceConfig";
        Number serverCount=(Number) queryForSingleValue(sql);//这个语句似乎可以返回任何类型的查询
        //System.out.println(bookCount);
        return serverCount.intValue();
    }

    @Override
    public List<TomcatAndHeartbeatServiceConfig> queryForPageItems(Integer begin, Integer pageSize) {
        String sql ="select `id`,`serverId`,`serviceId`,`tomcatHome`,`javaHome`,`maxMemory`,`httpPort`,`shutdownPort`,`projectId`,`moduleId`,`use`,`heartbeat` from t_tomcatAndHeartbeatServiceConfig limit ?,?";
        return queryForList(TomcatAndHeartbeatServiceConfig.class,sql,begin,pageSize);

    }
}
